package com.sztz.batch;

import cn.hutool.core.exceptions.ExceptionUtil;
import cn.hutool.json.JSONUtil;
import com.sztz.entity.FirmUser;
import lombok.extern.slf4j.Slf4j;
import org.springframework.batch.core.ItemWriteListener;

import java.util.List;

/**
 * 数据写入监听器
 * @author yzy
 * @date 2022/8/30 17:56
 */
@Slf4j
public class MyWriterListener implements ItemWriteListener<FirmUser> {
    @Override
    public void beforeWrite(List<? extends FirmUser> items) {
        log.info("beforeWrite size = {}", items.size());
    }

    @Override
    public void afterWrite(List<? extends FirmUser> items) {
        log.info("afterWrite size= {}, firmUser= {}",items.size(), JSONUtil.toJsonStr(items));
    }

    @Override
    public void onWriteError(Exception exception, List<? extends FirmUser> items) {
        log.error("onWriteError ={}", ExceptionUtil.stacktraceToString(exception));
    }
}
